import pandas as pd
import os
import time

start = time.time()
path = os.getcwd()
print(path)
fails = os.listdir(path)
print(fails)
path_new = None
for fail in fails:
    if 'new' in fail:
        print(fail)
        if fail.endswith('.csv'):
            fail = os.path.join(fail)
            path_new = fail
df = pd.read_csv(path_new)
print(df.head(5))
print(df.info)
print(df.columns)


def obtaintime(num):
    timearray = time.localtime(num)
    Timeconversion = time.strftime(r'%Y-%m-%d | %H:%M:%S ', timearray)
    return Timeconversion


df_time = df.DataTime
df_time = df_time.apply(obtaintime)
print(df_time)
valid = ['DeviceID', 'Longitude', 'Latitude', 'Speed', 'TimeStamp', 'Status']
df = df[valid]

df.dropna(how='any', inplace=True)
print(df.isna().sum())
print(df.shape[0])
df.drop_duplicates(inplace=True)
print(df.shape[0])

df['Longitude'] = df['Longitude'] / 1e7  # 标准化经纬度值
df['Latitude'] = df['Latitude'] / 1e7

df['data_time'] = df['TimeStamp'].apply(obtaintime)

print(df.head(5))

print(fr'{round(time.time() - start, 2)}秒')
